#!/bin/bash

echo "✅ 正在为萤窗后端生成完整测试数据..."

# 1. 创建用户（模拟微信登录）
echo "1. 创建用户..."
curl -X POST "http://localhost:8080/api/users/login?code=mock_code" \
  -H "Content-Type: application/json" \
  -d '{
    "openId": "test_user_001",
    "nickname": "温暖测试用户",
    "avatarUrl": "https://via.placeholder.com/64"
  }'

# 2. 创建时光胶囊（解锁时间为后天）
echo "2. 创建时光胶囊..."
curl -X POST "http://localhost:8080/api/capsules" \
  -H "Content-Type: application/json" \
  -H "X-User-Id: 1" \
  -d '{
    "title": "给未来的自己",
    "content": "当你看到这封信时，你已经在黑暗中多走了三公里。抬头看，星星一直在。",
    "unlockTime": "2025-10-10T00:00:00",
    "createdBy": {
      "id": 1
    }
  }'

# 3. 创建暖意句子
echo "3. 创建暖意句子..."
curl -X POST "http://localhost:8080/api/sentences" \
  -H "Content-Type: application/json" \
  -H "X-User-Id: 1" \
  -d '{
    "content": "世界很吵，但这里只为你安静",
    "collectedBy": {
      "id": 1
    }
  }'

curl -X POST "http://localhost:8080/api/sentences" \
  -H "Content-Type: application/json" \
  -H "X-User-Id: 1" \
  -d '{
    "content": "你正在做的事，让宇宙多了一分温柔",
    "collectedBy": {
      "id": 1
    }
  }'

curl -X POST "http://localhost:8080/api/sentences" \
  -H "Content-Type: application/json" \
  -H "X-User-Id: 1" \
  -d '{
    "content": "没关系，有些话适合慢慢说",
    "collectedBy": {
      "id": 1
    }
  }'

# 4. 启动善意传递链（基于上一步创建的胶囊 ID=1）
echo "4. 启动善意传递链..."
curl -X POST "http://localhost:8080/api/chains/start/1" \
  -H "Content-Type: application/json" \
  -H "X-User-Id: 1"

# 5. 向传递链添加节点
echo "5. 向传递链添加节点..."
curl -X POST "http://localhost:8080/api/chains/1/nodes?message=%E7%94%9F%E6%97%A5%E5%BF%AB%E4%B9%90" \
  -H "Content-Type: application/json" \
  -H "X-User-Id: 1"

curl -X POST "http://localhost:8080/api/chains/1/nodes?message=%E7%A5%9D%E4%BD%A0%E5%A4%A9%E5%A4%A9%E5%BC%80%E5%BF%83" \
  -H "Content-Type: application/json" \
  -H "X-User-Id: 1"

curl -X POST "http://localhost:8080/api/chains/1/nodes?message=%E8%AE%B0%E5%BE%97%E5%90%83%E8%9B%8B%E7%B3%95%E5%95%8A" \
  -H "Content-Type: application/json" \
  -H "X-User-Id: 1"

# 6. 手动解锁胶囊（模拟定时任务）
echo "6. 手动解锁胶囊..."
curl -X POST "http://localhost:8080/api/capsules/1/unlock" \
  -H "Content-Type: application/json" \
  -H "X-User-Id: 1"

echo "✅ 数据生成完成！现在前端调用接口将展示真实数据。"